package ee.rsi2m.goproject.service;

import ee.rsi2m.goproject.view.GoBoardView;
import ee.rsi2m.goproject.view.GoStoneView;

import android.graphics.Canvas;
import android.view.SurfaceHolder;

public class GoStoneThread extends Thread {
	
	private SurfaceHolder surfaceHolder;
    private GoStoneView stone;
    private boolean run = false;
 

    
    public GoStoneThread(SurfaceHolder surfaceHolder, GoStoneView stone) {
    	this.surfaceHolder=surfaceHolder;
    	this.stone=stone;
    }
    
    
 
    public void setRunning(boolean run) {
        this.run = run;
    }
 
    public void run() {
        Canvas c;
        while (run) {
            c = null;
            try {
                c = surfaceHolder.lockCanvas(null);
                synchronized (surfaceHolder) {
                	stone.onDraw(c);
                }
            } finally {
                if (c != null) {
                    surfaceHolder.unlockCanvasAndPost(c);
                }
            }
        }
    }

}
